#!/bin/env bash
if [ -z $BOT ]; then
    echo "code 45"
    exit 1
fi

case $BOT in
    trss|trss*|TRSS|TRSS*)
        NAME=TRSS-Yunzai
        URL=https://gitee.com/TimeRainStarSky/Yunzai;;
    miao|miao*|Miao|Miao*)
        NAME=Miao-Yunzai
        URL=https://gitee.com/yoimiya-kokomi/Miao-Yunzai
        URLA=https://github.com/yoimiya-kokomi/miao-plugin;;
    *) 
        echo "code 45"
        exit 1
esac
if [ -z "$DIR" ]; then
if [ -n "$ENV_CWD" ]; then
    DIR=$(realpath "$ENV_CWD/../$NAME")
else
    DIR="/root/bot/$NAME"
fi
fi
if ! command -v git; then
    echo "安装好环境包后使用"
    exit 1
fi

git clone --depth 1 $URL $DIR
[ ! -z $URLA ] && git clone --depth 1 $URLA $DIR/plugins/miao-plugin/
cd $DIR && pnpm i && pushd $DIR
echo -e "启动命令:\ncd $DIR\nnode app"